/*
 * Copyright 2012-2020. the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. More information from:
 *
 *        https://github.com/fenixsoft
 */

package com.xue.dao.ds2;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

import com.xue.dao.BaseEntity;

/**
 * 商品对象模型
 *
 * @author icyfenix@gmail.com
 * @date 2020/3/6 10:43
 */
@Entity
@Table(name = "product")
public class Product2 extends BaseEntity {

	@NotEmpty(message = "商品名称不允许为空")
	private String title;

	@NotNull(message = "商品应当有明确的价格")
	@Min(value = 0, message = "商品价格最低为零")
	// 这里是偷懒，正式场合使用BigDecimal来表示金额
	private Double price;

	@Min(value = 0, message = "评分最低为0")
	@Max(value = 10, message = "评分最高为10")
	private Float rate;

	private String description;

	private String cover;

	private String detail;

	@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
	@JoinColumn(name = "product_id")
	private Set<Specification2> specifications;

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public Double getPrice() {
		return price;
	}

	public void setPrice(Double price) {
		this.price = price;
	}

	public Float getRate() {
		return rate;
	}

	public void setRate(Float rate) {
		this.rate = rate;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getCover() {
		return cover;
	}

	public void setCover(String cover) {
		this.cover = cover;
	}

	public String getDetail() {
		return detail;
	}

	public void setDetail(String detail) {
		this.detail = detail;
	}

	public Set<Specification2> getSpecifications() {
		return specifications;
	}

	public void setSpecifications(Set<Specification2> specifications) {
		this.specifications = specifications;
	}

}
